package hotel.switchs.oversea.online.service.impl;

import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import hotel.base.oversea.utils.Result;
import hotel.switchs.oversea.api.entity.SwitchPushHotelLogEntity;
import hotel.switchs.oversea.online.mapper.SwitchPushHotelLogMapper;
import hotel.switchs.oversea.online.service.SwitchPushHotelLogService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import tk.mybatis.mapper.entity.Example;

import java.util.List;
import java.util.Map;

/**
 * @Auther: lmf
 * @Date: 2021/03/12/15:23
 * @Description:
 */
@Slf4j
@Service
public class SwitchPushHotelLogServiceImpl implements SwitchPushHotelLogService {
    @Autowired
    private SwitchPushHotelLogMapper switchPushHotelLogMapper;
    /***
     * @Author: lmf
     * @Date: 2021/3/12
     * 添加全日推送记录到表里
     */
    @Override
    public Result<Object> addPushHotelLog(SwitchPushHotelLogEntity switchPushHotelLogEntity) {
        Example example=new Example(SwitchPushHotelLogEntity.class);
        Example.Criteria criteria=example.createCriteria();
        criteria.andEqualTo("hotelId",switchPushHotelLogEntity.getHotelId());
        int count=switchPushHotelLogMapper.selectCountByExample(example);
        if(count>0){
            switchPushHotelLogMapper.updateByExampleSelective(switchPushHotelLogEntity,example);
        }else{
            switchPushHotelLogMapper.insert(switchPushHotelLogEntity);
        }
        return new Result<>();
    }
    /***
    * @Author: lmf
    * @Date: 2021/3/16
     * 获取全日推送记录列表
    */
    @Override
    public Result<Object> getPushHotelLog(Map<String, String> params) {
        Integer pageCode= Integer.valueOf(params.get("pageCode"));
        Integer pageSize= Integer.valueOf(params.get("pageSize"));
        PageHelper.startPage(pageCode, pageSize);
        List<SwitchPushHotelLogEntity> list = switchPushHotelLogMapper.selectAll();
        PageInfo<SwitchPushHotelLogEntity> pageInfo = new PageInfo<>(list);
        return new Result<>(pageInfo);
    }
    /***
    * @Author: lmf
    * @Date: 2021/3/16
     * 更新酒店的推送状态
    */
    @Override
    public Result<Object> modifyPushHotelStatus() {
        SwitchPushHotelLogEntity switchPushHotelLogEntity=new SwitchPushHotelLogEntity();
        switchPushHotelLogEntity.setPush(0);
        Example example=new Example(SwitchPushHotelLogEntity.class);
        Example.Criteria criteria=example.createCriteria();
        criteria.andCondition("id>0");
        switchPushHotelLogMapper.updateByExampleSelective(switchPushHotelLogEntity,example);
        return new Result<>();
    }


}
